package com.lrkj.payfee.controller;

import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lrkj.common.annotation.Log;
import com.lrkj.common.core.controller.BaseController;
import com.lrkj.common.core.domain.AjaxResult;
import com.lrkj.common.enums.BusinessType;
import com.lrkj.payfee.domain.RoomMeter;
import com.lrkj.payfee.service.IRoomMeterService;
import com.lrkj.common.utils.poi.ExcelUtil;
import com.lrkj.common.core.page.TableDataInfo;

/**
 * 房间仪表Controller
 *
 * @author yajun_ren
 * @date 2021-07-27
 */
@RestController
@RequestMapping("/payfee/meter")
public class RoomMeterController extends BaseController
{
    @Autowired
    private IRoomMeterService roomMeterService;

    /**
     * 查询房间仪表列表
     */
    @ApiOperation(value = "查询房间仪表列表", notes = "查询房间仪表列表")
    @GetMapping("/list")
    public TableDataInfo list(RoomMeter roomMeter)
    {
        startPage();
        List<RoomMeter> list = roomMeterService.selectRoomMeterList(roomMeter);
        return getDataTable(list);
    }

    /**
     * 导出房间仪表列表
     */
	@ApiOperation(value = "导出房间仪表列表", notes = "导出房间仪表列表")
    @PreAuthorize("@ss.hasPermi('payfee:meter:export')")
    @Log(title = "房间仪表", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RoomMeter roomMeter)
    {
        List<RoomMeter> list = roomMeterService.selectRoomMeterList(roomMeter);
        ExcelUtil<RoomMeter> util = new ExcelUtil<RoomMeter>(RoomMeter.class);
        return util.exportExcel(list, "房间仪表数据");
    }

    /**
     * 获取房间仪表详细信息
     */
	@ApiOperation(value = "获取房间仪表详细信息", notes = "获取房间仪表详细信息")
    @PreAuthorize("@ss.hasPermi('payfee:meter:query')")
    @GetMapping(value = "/{rometerId}")
    public AjaxResult getInfo(@PathVariable("rometerId") String rometerId)
    {
        return AjaxResult.success(roomMeterService.selectRoomMeterById(rometerId));
    }

    /**
     * 新增房间仪表
     */
    @Transactional
    @ApiOperation(value = "新增房间仪表", notes = "新增房间仪表")
    @PreAuthorize("@ss.hasPermi('payfee:meter:add')")
    @Log(title = "房间仪表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RoomMeter roomMeter)
    {
        return toAjax(roomMeterService.insertRoomMeter(roomMeter));
    }

    /**
     * 修改房间仪表
     */
	 @ApiOperation(value = "修改房间仪表", notes = "修改房间仪表")
    @PreAuthorize("@ss.hasPermi('payfee:meter:edit')")
    @Log(title = "房间仪表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RoomMeter roomMeter)
    {
        return toAjax(roomMeterService.updateRoomMeter(roomMeter));
    }

    /**
     * 删除房间仪表
     */
	 @ApiOperation(value = "删除房间仪表", notes = "删除房间仪表")
    @PreAuthorize("@ss.hasPermi('payfee:meter:remove')")
    @Log(title = "房间仪表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rometerIds}")
    public AjaxResult remove(@PathVariable String[] rometerIds)
    {
        return toAjax(roomMeterService.deleteRoomMeterByIds(rometerIds));
    }
}
